Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
When using "and" in ruby, the earth is flat

As I have always been taught in logic, the "and" operator means both values must be true, for the entire statement to be true. If you have many statements chained with "and", then any one of them being false should make the whole claim false. In Ruby, however, I ran into this scenario:

horizon_flat = true
one_up_and_down = true
magellan_fell = false
flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell

puts("Hey ruby, doesn't the horizon look flat?")
puts(horizon_flat) # true

puts("Isn't there only one up and one down?")
puts(one_up_and_down) # true

puts("Did Magellan fall off the earth?")
puts(magellan_fell) # false

puts("Is the earth flat?")
puts(flat_earth_thesis) # true

Strangely, if I just run the statement itself, it returns false correctly puts(horizon_flat and one_up_and_down and magellan_fell) # false

But if I store that statement in a variable, and later call it, the variable outputs true. Why does ruby think the earth is flat?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

While you expect this:

flat_earth_thesis = horizon_flat and one_up_and_down and magellan_fell

To be evaluated as:

flat_earth_thesis = (horizon_flat and one_up_and_down and magellan_fell)

It is instead evaluated as:

(flat_earth_thesis = horizon_flat) and one_up_and_down and magellan_fell

As noted in comments, review operator precedence.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!